package com.neusoft.elm_servlet.controller;

import java.sql.SQLException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neusoft.elm_servlet.po.Orders;
import com.neusoft.elm_servlet.service.OrdersService;
import com.neusoft.elm_servlet.service.impl.OrdersServiceImpl;

public class OrdersController {
	
	OrdersService ordersService = new OrdersServiceImpl();

	public int createOrders(HttpServletRequest request,HttpServletResponse response){
		//userId、businessId、daId、orderTotal
		String userId = request.getParameter("userId");
		String businessId = request.getParameter("businessId");
		String daId = request.getParameter("daId");
		String orderTotal = request.getParameter("orderTotal");
		Orders orders = new Orders();
		orders.setUserId(userId);
		orders.setBusinessId(Integer.valueOf(businessId));
		orders.setDaId(Integer.valueOf(daId));
		orders.setOrderTotal(Double.valueOf(orderTotal));
		
		int orderId = 0;
		try {
			orderId = ordersService.createOrders(orders);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return orderId;
	}
	
	public Orders getOrdersById(HttpServletRequest request,HttpServletResponse response){
		String orderId = request.getParameter("orderId");
		Orders orders = null;
		try {
			orders = ordersService.getOrdersById(orderId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return orders;
	}
	
	public List<Orders> listOrdersByUserId(HttpServletRequest request,HttpServletResponse response){
		String userId = request.getParameter("userId");
		List<Orders> list = null;
		try {
			list = ordersService.listOrdersByUserId(userId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
}
